home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000…tember: Reference Library / Dev.CD Sep 00 RL Disk 1.toast / mac / Technical Documentation / Develop / develop Issue 28 / develop Issue 28 code / MacApp Debugging / TwistDownLists / UTwistDownView.cp < prev    next >
Encoding:
Text File  |  1996-09-23  |  59.0 KB  |  1,772 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UTwistDownView.cp
  3. // ETO20 MacApp 3.3.1, MPW 3.4.1
  4. // Copyright ©1994-1996 Conrad Kopala
  5. // Twist Down Lists version 2.0a0 7/15/96
  6. //----------------------------------------------------------------------------------------
  7.  
  8. #ifndef __UTWISTDOWNVIEW__
  9. #include "UTwistDownView.h"
  10. #endif
  11.  
  12. #ifndef __UTWISTDOWNAPP__
  13. #include "UTwistDownApp.h"
  14. #endif
  15.  
  16. #ifndef __UTWISTDOWNDOCUMENT__
  17. #include "UTwistDownDocument.h"
  18. #endif
  19.  
  20. #ifndef __UTWISTDOWNELEMENT__
  21. #include "UTwistDownElement.h"
  22. #endif
  23.  
  24. #ifndef __UTWISTDOWNCONTROL__
  25. #include "UTwistDownControl.h"
  26. #endif
  27.  
  28. //MacApp stuff
  29. #ifndef __UMACAPPUTILITIES__
  30. #include "UMacAppUtilities.h"
  31. #endif
  32.  
  33. #ifndef __UMENUMGR__
  34. #include "UMenuMgr.h"
  35. #endif
  36.  
  37. #ifndef __UVIEWSERVER__
  38. #include "UViewServer.h"
  39. #endif
  40.  
  41. #ifndef __UWINDOW__
  42. #include "UWindow.h"
  43. #endif
  44.  
  45. //ToolBox stuff
  46. #ifndef __FONTS__
  47. #include "Fonts.h"
  48. #endif
  49.  
  50. #ifndef __QUICKDRAWTEXT__
  51. #include "QuickdrawText.h"
  52. #endif
  53.  
  54. #ifndef __SCRIPT__
  55. #include "Script.h"
  56. #endif
  57.  
  58. #ifndef __AEREGISTRY__
  59. #include "AERegistry.h"
  60. #endif
  61.  
  62. //ANSI stuff
  63. //None
  64. //----------------------------------------------------------------------------------------
  65. // Constants:
  66.  
  67.     
  68. //========================================================================================
  69. // Global Procedures
  70. //========================================================================================
  71. #undef Inherited
  72.  
  73. //----------------------------------------------------------------------------------------
  74. // InitUTwistDownView: 
  75. //----------------------------------------------------------------------------------------
  76. #pragma segment DlgInit
  77.  
  78. void InitUTwistDownView()
  79. {
  80.  
  81.     MA_REGISTER_CLASS(TTwistDownView);
  82.     MA_REGISTER_CLASS(TChangeFontSizeDialog);
  83.     
  84. }
  85.  
  86. //========================================================================================
  87. // CLASS TTwistDownView
  88. //========================================================================================
  89. #undef Inherited
  90. #define Inherited TTextListView
  91.  
  92. #pragma segment GVOpen
  93. MA_DEFINE_CLASS_M2(TTwistDownView, Inherited, MScriptableObject);
  94. //----------------------------------------------------------------------------------------
  95. // TTwistDownView constructor
  96. //----------------------------------------------------------------------------------------
  97. #pragma segment GVOpen
  98. TTwistDownView::TTwistDownView(): MScriptableObject(cTwistDownView)
  99. {
  100. fTwistDownDocument = NULL;
  101. fTwistDownControlSize = gZeroVPt;
  102.  
  103. fOpenTriangle = NULL;
  104. fClosedTriangle = NULL;
  105. fIntermediateTriangle = NULL;
  106.  
  107. fCouldExpandAll = FALSE;
  108. fCouldCollapseAll = FALSE;
  109.  
  110. fHandlesFirstClicks = FALSE;
  111. fIsFirstClick = TRUE;
  112.  
  113. fNumberOfControls = 0;
  114. fInitialNumberOfControls = 0;
  115. fNumberOfExpandedControls = 0;
  116. fNumberOfCollapsedControls = 0;
  117.  
  118. fControlCountingEnabled = FALSE;
  119.  
  120. fWritingDirection = leftToRight;    //assume left to right
  121. fTwistDownControlLocation.v = 0;
  122. fTwistDownControlLocation.h = 0;
  123.  
  124. #if qDebug
  125. this -> PrintAppConstructorClassInfo();
  126. #endif
  127.  
  128. }
  129. //----------------------------------------------------------------------------------------
  130. // TTwistDownView::~TTwistDownView
  131. //----------------------------------------------------------------------------------------
  132. #pragma segment GVClose
  133. TTwistDownView::~TTwistDownView()
  134. {
  135.  
  136. fTwistDownDocument = NULL;
  137. fTwistDownControlSize = gZeroVPt;
  138.  
  139. if (fOpenTriangle)
  140.     {
  141.         KillPoly(fOpenTriangle);
  142.         fOpenTriangle = NULL;
  143.     }
  144.  
  145. if (fClosedTriangle)
  146.     {
  147.         KillPoly(fClosedTriangle);
  148.         fClosedTriangle = NULL;
  149.     }
  150.  
  151. if (fIntermediateTriangle)
  152.     {
  153.         KillPoly(fIntermediateTriangle);
  154.         fIntermediateTriangle = NULL;
  155.     }
  156.  
  157. fCouldExpandAll = FALSE;
  158. fCouldCollapseAll = FALSE;
  159.  
  160. fNumberOfControls = 0;
  161. fInitialNumberOfControls = 0;
  162. fNumberOfExpandedControls = 0;
  163. fNumberOfCollapsedControls = 0;
  164.  
  165. fControlCountingEnabled = FALSE;
  166.  
  167. #if qDebug
  168. this -> PrintAppDestructorClassInfo();
  169. #endif
  170.  
  171. }
  172. //----------------------------------------------------------------------------------------
  173. // TTwistDownView::ITwistDownView:
  174. //----------------------------------------------------------------------------------------
  175. #pragma segment AOpen
  176. void TTwistDownView::ITwistDownView(TTwistDownDocument* itsTwistDownDocument, TView* itsSuperView,
  177.                                          const VPoint& itsLocation, const VPoint& itsSize)
  178. {
  179.  
  180. short numOfItems = 0;                        // Number of items initially 
  181. short rowHeight = 0;                        // Row height, or zero for font height 
  182. short colWidth = 200;                        // Width of items in the columns 
  183. Boolean adornRows = FALSE;            // Draw the row adornments? 
  184. Boolean adornCols = FALSE;            // Draw the col adornment? 
  185. short rowInset = 0;                            // Amount to inset the rows 
  186. short colInset = 0;                            // Amount to inset the column 
  187. Boolean singleSelection = TRUE;    // single cell selection? 
  188.     
  189. this -> ITextListView(itsTwistDownDocument,itsSuperView,itsLocation,itsSize,sizeVariable,sizeVariable,
  190.                                   numOfItems,rowHeight,colWidth,adornRows,adornCols,rowInset,colInset,singleSelection,
  191.                                   gApplicationStyle);
  192.  
  193. fTwistDownDocument = itsTwistDownDocument;
  194.  
  195. //Let's set the fWritingDirection to the current system direction.
  196. if (GetSysDirection() == 0)
  197.     fWritingDirection = leftToRight;
  198. else
  199.     fWritingDirection = rightToLeft;
  200.  
  201. if (fWritingDirection == leftToRight)
  202.         fJustification = teFlushDefault;
  203. else
  204.         fJustification = teFlushRight;
  205.         
  206. this -> CreateTwistDownTriangles();
  207. }
  208. //----------------------------------------------------------------------------------------
  209. // TTwistDownView::DoPostCreate:
  210. //----------------------------------------------------------------------------------------
  211. #pragma segment AOpen
  212. void TTwistDownView::DoPostCreate(TDocument* itsDocument)
  213. {
  214.  
  215. Inherited::DoPostCreate(itsDocument);    
  216. fTwistDownDocument = (TTwistDownDocument*)itsDocument;
  217.  
  218. //Let's set the fWritingDirection to the current system direction.
  219. if (GetSysDirection() == 0)
  220.     fWritingDirection = leftToRight;
  221. else
  222.     fWritingDirection = rightToLeft;
  223.     
  224. if (fWritingDirection == leftToRight)
  225.         fJustification = teFlushDefault;
  226. else
  227.         fJustification = teFlushRight;
  228.  
  229. FailInfo fi;
  230. Try(fi)
  231. {
  232.     this -> CreateTwistDownTriangles();
  233.     OSErr myOSErr = noErr;
  234.     
  235.     if (fTwistDownDocument)
  236.         myOSErr = this -> CreateVisibleList();
  237.     
  238.     if (myOSErr != noErr)
  239.         Failure(myOSErr, 0);
  240.         
  241.     fi.Success();
  242. }
  243. else // Recover
  244. {
  245.     fi.ReSignal();
  246. }            
  247.     
  248. }
  249. //----------------------------------------------------------------------------------------
  250. // TTwistDownView::DoSetupMenus:
  251. //----------------------------------------------------------------------------------------
  252. #pragma segment ARes
  253. void TTwistDownView::DoSetupMenus()
  254. {
  255.     long numberOfItemsInList = 0;
  256.     
  257. //The average user will probably never encounter a situation where the list is empty.
  258. //However, I can make a volume that is empty and so, I figure there is at least one
  259. //other malicious person out there who will do it too. Using your favorite disk editor, 
  260. //set all IsInvisible flags. When you open the disk in Twist Down Lists, it will appear 
  261. //to be empty unless you set Twist Down Lists to Show Invisibles. 
  262.  
  263.     if (fTwistDownDocument)
  264.         numberOfItemsInList = fTwistDownDocument -> GetNumberOfItemsInList();
  265.     
  266.     MenuRef aMenuRef;
  267.     TextStyle aStyle;    
  268.     CStr255 aName;
  269.     short theFont;
  270.     short nItems;
  271.     Style aFace;
  272.     
  273.     Inherited::DoSetupMenus();
  274.     
  275.     Boolean haveMemory = !MemSpaceIsLow();
  276.     
  277.     aStyle = fTextStyle;
  278.     
  279.     aMenuRef = MAGetMenu(mFontMenu);
  280.     
  281. //Font menu setup copied from DemoText:UTEDocument.cp
  282.     if (aMenuRef)
  283.     {
  284.     
  285.         GetFontName(aStyle.tsFont, aName);            // Get real font number in case tsFont is 
  286.         GetFNum(aName, &theFont);                                // …the system or application font. 
  287.         nItems = CountMItems(aMenuRef);
  288.         for (short item = 1; item <= nItems; ++item)
  289.         {
  290.             if (item <= 31)
  291.                 EnableItem(aMenuRef, item);
  292.                             
  293.                 short fnt;
  294.     
  295.                 GetMenuItemText(aMenuRef, item, aName);
  296.                 GetFNum(aName, &fnt);
  297.                 CheckItem(aMenuRef, item, (fnt == theFont));
  298.         
  299.         }
  300.     }
  301.  
  302. //Note: The cFont commands are enabled only if there is something in the list.
  303.     Enable(cFont, numberOfItemsInList > 0);
  304.  
  305. //Note: Font size menu setup copied from DemoText:UTEDocument.cp
  306.     for (CommandNumber c = cFontSizeMin; c <= cFontSizeMax; ++c)
  307.     {
  308.         Boolean checkSize;
  309.         
  310.         checkSize = ((c - cFontSizeBase) == aStyle.tsSize);
  311.  
  312.         EnableCheck(c, numberOfItemsInList > 0, checkSize);
  313.         
  314.         if (RealFont(aStyle.tsFont, (short) (c - cFontSizeBase)))
  315.             aFace = outline;                // …then we outline it 
  316.         else
  317.             aFace = 0;
  318.             
  319.         SetStyle(c, aFace);
  320.     }
  321.  
  322. //Note: The cLargerFontSize, cSmallerFontSize, and  cOtherFontSize commands are enabled 
  323. //only if there is something in the list.
  324.     Enable(cLargerFontSize, numberOfItemsInList > 0);
  325.     Enable(cSmallerFontSize, numberOfItemsInList > 0);
  326.     Enable(cOtherFontSize, numberOfItemsInList > 0);
  327.         
  328.     Enable(cExpandAll, fCouldExpandAll);
  329.     Enable(cCollapseAll, fCouldCollapseAll);    //This should always be available except 
  330.                                                                                         //when the list is already collapsed because
  331.                                                                                         //it can help the user get out of a low
  332.                                                                                         //memory situation.
  333.  
  334. CStr255 menuItemName = gEmptyString;
  335.  
  336. if (fWritingDirection == leftToRight)
  337.     SetIndividualCommandName(cWritingDirection, kMenuNameStrings, kRightToLeftNameIdx);
  338. else if(fWritingDirection == rightToLeft)
  339.     SetIndividualCommandName(cWritingDirection, kMenuNameStrings, kLeftToRightNameIdx);
  340.  
  341. Enable(cWritingDirection, !gUseSystemDirection && numberOfItemsInList > 0);
  342.  
  343. }
  344. //----------------------------------------------------------------------------------------
  345. // TTwistDownView::DoMenuCommand:
  346. //----------------------------------------------------------------------------------------
  347. #pragma segment ASelCommand
  348. void TTwistDownView::DoMenuCommand(CommandNumber aCommandNumber)
  349. {
  350.  
  351.     CStr255 newFontName;
  352.     short menu;
  353.     short item;
  354.     short newFontSize;
  355.     TextStyle newStyle;
  356.     
  357.     newStyle = fTextStyle;
  358.     
  359. //Note: DoMenuCommand for mFontMenu follows after DemoText:UTEDocument.cp    
  360.     CommandToMenuItem(aCommandNumber, menu, item);
  361.  
  362.     if (menu == mFontMenu)
  363.         {        
  364.             GetMenuItemText(MAGetMenu(menu), item, newFontName);
  365.             GetFNum(newFontName, &(newStyle.tsFont));
  366.  
  367.             if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  368.                 {
  369.                     TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  370.                     theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, fTwistDownDocument, pFontName);
  371.                     CTempDesc theNewFont;
  372.                     theNewFont.PutString(newFontName);
  373.                     theEvent -> WriteParameter(keyAEData, theNewFont);
  374.                     TAppleEvent * theReply = theEvent -> Send();
  375.                     FreeIfObject(theEvent);
  376.                     FreeIfObject(theReply);
  377.                 }
  378.             else
  379.                 this -> DoChangeFont(newFontName);
  380.         }
  381.         
  382. //Note: The following else if clause follows after DemoText:UTEDocument.cp except for the fact
  383. //that DemoText doesn't do AppleEvents.
  384.     else if ((aCommandNumber > cFontSizeBase) && (aCommandNumber <= cFontSizeMax))
  385.         {
  386.             
  387.             newFontSize = (short)(aCommandNumber - cFontSizeBase);
  388.  
  389.             if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  390.                 {
  391.                     TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  392.                     theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, fTwistDownDocument, pPointSize);
  393.                     CTempDesc theNewFontSize;
  394.                     long theFontSize = long(newFontSize);
  395.                     theNewFontSize.PutLong(theFontSize);
  396.                     theEvent -> WriteParameter(keyAEData, theNewFontSize);
  397.                     TAppleEvent * theReply = theEvent -> Send();
  398.                     FreeIfObject(theEvent);
  399.                     FreeIfObject(theReply);
  400.                 }
  401.             else
  402.                 this -> DoChangeFontSize(newFontSize);
  403.         
  404.         }        
  405.     else    
  406.         switch (aCommandNumber) 
  407.             {
  408. //Note:  These two cases follow after DemoText:UTEDocument.cp cGrowSize and cGrowShrink.
  409. //Except for the fact that DemoText doesn't do AppleEvents.
  410.                 case cLargerFontSize:
  411.                 case cSmallerFontSize:
  412.                     {
  413.                         //Note that no limits are put on newFontSize. That's because it's fun and
  414.                         //it hasn't broken anything yet.
  415.                         newFontSize = fTextStyle.tsSize;
  416.                         if (aCommandNumber == cLargerFontSize)
  417.                             newFontSize = newFontSize + 1;
  418.                         else
  419.                             newFontSize = newFontSize - 1;
  420.  
  421.                         if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  422.                             {
  423.                                 TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  424.                                 theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, fTwistDownDocument, pPointSize);
  425.                                 CTempDesc theNewFontSize;
  426.                                 long theFontSize = long(newFontSize);
  427.                                 theNewFontSize.PutLong(theFontSize);
  428.                                 theEvent -> WriteParameter(keyAEData, theNewFontSize);
  429.                                 TAppleEvent * theReply = theEvent -> Send();
  430.                                 FreeIfObject(theEvent);
  431.                                 FreeIfObject(theReply);
  432.                             }
  433.                         else
  434.                             this -> DoChangeFontSize(newFontSize);
  435.                     }
  436.                 break;
  437.                 
  438. //Note: DemoText:UTEDocument.cp hasn't implemented cOtherFontSize (cOtherSize) yet (as of ETO19)
  439.                 case cOtherFontSize:
  440.                     {
  441.                         long fontSize = 0;
  442.                         fontSize = (long)newStyle.tsSize;
  443.                         
  444.                         if (this -> GetNewFontSize(cOtherFontSize,fontSize))
  445.                             {
  446.                                 newFontSize = (short)fontSize;
  447.  
  448.                                 if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  449.                                     {
  450.                                         TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  451.                                         theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, fTwistDownDocument, pPointSize);
  452.                                         CTempDesc theNewFontSize;
  453.                                         long theFontSize = long(newFontSize);
  454.                                         theNewFontSize.PutLong(theFontSize);
  455.                                         theEvent -> WriteParameter(keyAEData, theNewFontSize);
  456.                                         TAppleEvent * theReply = theEvent -> Send();
  457.                                         FreeIfObject(theEvent);
  458.                                         FreeIfObject(theReply);
  459.                                     }
  460.                                 else
  461.                                     this -> DoChangeFontSize(newFontSize);
  462.                             }
  463.                     }    //end case cOtherFontSize
  464.                 break;
  465.  
  466.                 case cExpandAll:
  467.                     {
  468.                     //There is no need to check fCouldExpandAll here because this is a menu command.
  469.                     //If the cExpandAll command is enabled it is ok to do it.
  470.                         TExpandAllCommand* anExpandAllCommand = new TExpandAllCommand;
  471.                         anExpandAllCommand -> IExpandAllCommand(fTwistDownDocument, this);
  472.                         if (gSendAppleEvents)
  473.                             anExpandAllCommand -> fUseAppleEvent = TRUE;
  474.                         this -> PostCommand(anExpandAllCommand);
  475.                     }    //end case cExpandAll
  476.                 break;
  477.                 
  478.                 case cCollapseAll:
  479.                     {                
  480.                     //There is no need to check fCouldCollapseAll here because this is a menu command.
  481.                     //If the cCollapseAll command is enabled it is ok to do it.
  482.                     //Because we don't want this to fail for out of memory reasons,
  483.                     //allocate it from temporary memory.    //PGMacApp 550
  484.                         Boolean oldTemp = TemporaryAllocation(TRUE);
  485.                         Boolean oldArrayPerm = AllocateObjectsFromPerm(FALSE);
  486.                             TCollapseAllCommand* aCollapseAllCommand = new TCollapseAllCommand;        
  487.                             aCollapseAllCommand -> ICollapseAllCommand(fTwistDownDocument, this);
  488.                             if (gSendAppleEvents)
  489.                                 aCollapseAllCommand -> fUseAppleEvent = TRUE;
  490.                             this -> PostCommand(aCollapseAllCommand);
  491.                         oldArrayPerm = AllocateObjectsFromPerm(oldArrayPerm);
  492.                         oldTemp = TemporaryAllocation(oldTemp);
  493.                     }    //end case cCollapseAll
  494.                 break;
  495.  
  496.                 case cWritingDirection:
  497.                     {
  498.                         EWritingDirection newWritingDirection;
  499.                         if (fWritingDirection == rightToLeft)
  500.                             newWritingDirection = leftToRight;
  501.                         else if (fWritingDirection == leftToRight)
  502.                             newWritingDirection = rightToLeft;
  503.                             
  504.                         if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  505.                             {
  506.                                 TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  507.                                 theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pWritingDirection);
  508.                                 CTempDesc theNewWritingDirection;
  509.                                 
  510.                                 if (newWritingDirection == leftToRight)
  511.                                     theNewWritingDirection.PutEnum(kAELeftToRight);
  512.                                 else if (newWritingDirection == rightToLeft)
  513.                                     theNewWritingDirection.PutEnum(kAERightToLeft);
  514.                                     
  515.                                 theEvent -> WriteParameter(keyAEData, theNewWritingDirection);
  516.                                 TAppleEvent * theReply = theEvent -> Send();
  517.                                 FreeIfObject(theEvent);
  518.                                 FreeIfObject(theReply);
  519.                             }
  520.                         else
  521.                             this -> DoChangeWritingDirection(newWritingDirection);        
  522.  
  523.                     }
  524.                 break;
  525.                 
  526.                 default:
  527.                     Inherited::DoMenuCommand(aCommandNumber);
  528.                 break;
  529.         }    //end switch
  530. }
  531. //----------------------------------------------------------------------------------------
  532. // TTwistDownView::HandleMouseDown: 
  533. //----------------------------------------------------------------------------------------
  534. #pragma segment ASelCommand
  535. Boolean TTwistDownView::HandleMouseDown(const VPoint& theMouse,TToolboxEvent* event, 
  536.                                                         CPoint hysteresis,EMouseDownType    mouseDownType)
  537.                                  
  538. {
  539. //This is saved here so TTwistDownControl::DoMouseUp can know if a mouseUp event
  540. //is associated with a first click mouseDown event. It it is, TTwistDownControl::DoMouseUp
  541. //will swallow the mouseUp event.
  542.  
  543. fIsFirstClick = (mouseDownType == kFirstClick_dragOnly || mouseDownType == kFirstClick_dragOrClick);
  544.  
  545. return Inherited::HandleMouseDown(theMouse,event,hysteresis,mouseDownType);
  546. }
  547. //----------------------------------------------------------------------------------------
  548. // TTwistDownView::GetViewSize:
  549. //----------------------------------------------------------------------------------------
  550. #pragma segment ARes
  551. void TTwistDownView::GetViewSize(VPoint& viewSize)
  552. {
  553. viewSize = fSize;
  554. }
  555. //----------------------------------------------------------------------------------------
  556. // TTwistDownView::CreateVisibleList:  used by TTwistDownView::DoPostCreate:
  557. //----------------------------------------------------------------------------------------
  558. #pragma segment AOpen
  559. OSErr TTwistDownView::CreateVisibleList()
  560. {
  561. OSErr myOSErr = noErr;
  562.  
  563. myOSErr = this -> BuildVisibleList( 0); //I'd be very surprised if we ever got an error here!
  564.  
  565. if (myOSErr == noErr)
  566.     {
  567.         short rowNumber = 0;
  568.  
  569.         this -> AddTwistDownControls(fTwistDownDocument -> GetHeadOfList(), rowNumber, myOSErr);
  570.         
  571.         if (myOSErr == noErr)
  572.             {
  573.                 this -> ResizeTwistDownViewRows();
  574.                 fControlCountingEnabled = TRUE;
  575.                 //Now set the enabling conditions for cExpandAll and cCollapseAll
  576.                 this -> SetTheCouldFlags();
  577.             }
  578.     }
  579.     
  580. return myOSErr;
  581. }
  582. //----------------------------------------------------------------------------------------
  583. // TTwistDownView::BuildVisibleList:    used by
  584. //                                                                        TTwistDownView::CreateVisibleList
  585. //                                                                        TTwistDownDocument::ExpandElement
  586. //                                                                        TTwistDownDocument::CollapseElement
  587. //                                                                        TTwistDownDocument::ExpandAll
  588. //                                                                        TTwistDownDocument::CollapseAll
  589. //                                                                        TExpandAllCommand::DoIt                                                                        
  590. //----------------------------------------------------------------------------------------
  591. #pragma segment ARes
  592. OSErr TTwistDownView::BuildVisibleList(short rowNumber)
  593. {
  594. OSErr myOSErr = noErr;        
  595. long numberOfRows = 0;                        //How many we need    to show
  596. short    currentNumberOfRows = 0;        //How many are in the list
  597. short numberOfRowsToInsert = 0;
  598. short numberOfRowsToDelete = 0;
  599.  
  600. currentNumberOfRows = fNumOfRows;
  601.  
  602. numberOfRows = fTwistDownDocument -> CountVisibleElements(fTwistDownDocument -> GetHeadOfList());
  603.  
  604. if (numberOfRows <= (long)kMaxNumberOfItemsToDisplay)
  605.     {
  606.         if (currentNumberOfRows == 0)                                                    //we're starting out
  607.             {
  608.                 numberOfRowsToInsert = (short)numberOfRows;
  609.                 this -> InsItemLast(numberOfRowsToInsert);
  610.             }
  611.         else
  612.             {
  613.                 if (currentNumberOfRows > (short)numberOfRows)                        //we're collapsing the list
  614.                     {
  615.                         numberOfRowsToDelete = currentNumberOfRows - (short)numberOfRows;
  616.                         this -> DelItemAt(rowNumber, numberOfRowsToDelete);
  617.                     }
  618.                 else if (currentNumberOfRows < (short)numberOfRows)            //we're expanding the list
  619.                     {
  620.                         numberOfRowsToInsert = (short)numberOfRows - currentNumberOfRows;
  621.                         if (rowNumber > currentNumberOfRows)
  622.                             this -> InsItemLast(numberOfRowsToInsert);    //The last element is being expanded.
  623.                         else
  624.                             this -> InsItemBefore(rowNumber, numberOfRowsToInsert);
  625.                     
  626.                     }
  627.                 else
  628.                     {
  629.                     // Do nothing, currentNumberOfRows == (short)numberOfRows -- an empty folder.
  630.                     }
  631.             }
  632.     }
  633.     else
  634.         myOSErr = errTooManyRows;
  635.  
  636. return myOSErr;        
  637. }
  638. //----------------------------------------------------------------------------------------
  639. // TTwistDownView::ResizeTwistDownViewRows:
  640. //----------------------------------------------------------------------------------------
  641. //This adjusts the size of the view to accomodate the precise number of rows in the view.
  642. #pragma segment ARes
  643. void TTwistDownView::ResizeTwistDownViewRows()
  644. {
  645.     
  646. short rowHeight = 0;
  647. VPoint viewSize = gZeroVPt;
  648. short numberOfRows = 0;
  649. VRect viewRect = gZeroVRect;
  650. long numberOfItemsInList = fTwistDownDocument -> GetNumberOfItemsInList();
  651. short newColumnWidth = 0;
  652.  
  653. if (numberOfItemsInList > 0)
  654.     {
  655.         this -> GetViewSize(viewSize);
  656.         rowHeight = this -> GetRowHeight(1);
  657.         viewSize.v = (VCoordinate)(rowHeight * fNumOfRows);
  658.     }
  659.  
  660.  
  661. this -> Resize(viewSize, TRUE);
  662.  
  663. viewRect.right = viewSize.h;
  664. viewRect.bottom = viewSize.v;
  665. this -> InvalidateVRect(viewRect);
  666.  
  667. }
  668. //----------------------------------------------------------------------------------------
  669. // TTwistDownView::CalculateColumnWidth:
  670. //----------------------------------------------------------------------------------------
  671. //The intent of this routine is to intelligently set the column width of the twistDownView.
  672. //It has been tested but is not currently being used.
  673. #pragma segment ARes
  674. short TTwistDownView::CalculateColumnWidth()
  675. {
  676. short maxIndentLevel = 0;
  677. short maxTextWidth = 0;
  678. short newColumnWidth = 0;
  679.  
  680. fTwistDownDocument -> CalculateColWidthParams(fTwistDownDocument -> GetHeadOfList(),maxIndentLevel,maxTextWidth);
  681.                                                                                                                         
  682. newColumnWidth = (maxIndentLevel + 1)*(short)fTwistDownControlSize.h + maxTextWidth;
  683.         
  684. if (newColumnWidth >= kMaxShort)
  685.     newColumnWidth = kMaxShort;
  686.  
  687. return newColumnWidth;
  688. }
  689. //----------------------------------------------------------------------------------------
  690. // TTwistDownView:::RevealRight: 
  691. //----------------------------------------------------------------------------------------
  692. #pragma segment ARes
  693. void TTwistDownView::RevealRight(Boolean redraw)
  694. {
  695. //This routine can be made to work better.
  696.     VPoint thePoint = gZeroVPt;
  697.     thePoint.h = fSize.h;
  698.  
  699.     this -> RevealRect(VRect(fSize.h,gZeroVPt.v,fSize.h,gZeroVPt.v),thePoint, redraw);
  700. }
  701. //----------------------------------------------------------------------------------------
  702. // TTwistDownView::SuperViewChangedFrame: 
  703. //----------------------------------------------------------------------------------------
  704. #pragma segment ARes
  705. void TTwistDownView::SuperViewChangedFrame(const VRect& oldFrame,const VRect& newFrame,Boolean invalidate)
  706. {
  707. //When the size of the TWindow holding this twistDownView is changed and, in particular, if
  708. //the writingDirection is right-to-left, it is necessary that the twistDownControls in this
  709. //view be pinned to the right side of the twistDownView and consequently the right side of the
  710. //TWindow holding this view. This is where that is done by setting fTwistDownControlLocation.h
  711. //to the proper value. 
  712.  
  713. //At present, when windows are resized, it is done on the right side of the window. It will
  714. //be interesting to see how this works when windows can be resized from either the left or right side.
  715.  
  716.     Inherited:: SuperViewChangedFrame(oldFrame,newFrame,invalidate);
  717.     
  718. //The following code can be made much more elegant.     
  719.     if (fWritingDirection == leftToRight)
  720.         {
  721.             fTwistDownControlLocation.h = 0;
  722.             this -> RevealTop(kRedraw);
  723.         }
  724.     else
  725.         {
  726.             if (this -> GetItemWidth() < (short)fSize.h)
  727.                 this -> SetItemWidth((short)fSize.h);
  728.             else if (this -> GetItemWidth() > kMaxShort)
  729.                 this -> SetItemWidth(kMaxShort);
  730.         
  731.             fTwistDownControlLocation.h = fSize.h - fTwistDownControlSize.h;
  732.             this -> RevealRight(kRedraw);            
  733.         }
  734.  
  735. }
  736. //----------------------------------------------------------------------------------------
  737. // TTwistDownView::NewTwistDownControl: used by TTwistDownView::AddTwistDownControls:
  738. //----------------------------------------------------------------------------------------
  739. #pragma segment ARes
  740. TTwistDownControl* TTwistDownView::NewTwistDownControl(TTwistDownElement* twistDownElement, VPoint& itsLocation, OSErr& myOSErr)
  741. {
  742. TTwistDownControl* newTwistDownControl = NULL;
  743.  
  744. FailInfo fi;
  745. Try(fi)
  746.     {    
  747.         FailNIL(newTwistDownControl = new TTwistDownControl);
  748.         newTwistDownControl -> ITwistDownControl(itsLocation, twistDownElement, this);
  749.         
  750.     //Note: To properly use the FailHere type test, always initialize the object whose failure 
  751.     //you're simulating before signalling Failure(errFailHere, 0);. If you don't the failure recovery
  752.     //won't work when it attempts to free the object.    
  753.         if (gFailHere)
  754.             {
  755.                 CStr63 failHereText = "FailHere";
  756.                 CStr63 displayedText = gEmptyString;
  757.                 twistDownElement -> GetDisplayedText(displayedText);
  758.                 if (failHereText == displayedText)
  759.                     Failure(errFailHere, 0);
  760.             }
  761.                     
  762.         if (newTwistDownControl != NULL && twistDownElement -> TestShowSubListFlag())
  763.             fNumberOfExpandedControls++;    //We're adding a control that should be shown expanded.
  764.         else
  765.             fNumberOfCollapsedControls++;    //We're adding a control that should be shown collapsed.    
  766.  
  767.         fi.Success();
  768.     }
  769. else
  770.     {
  771.         myOSErr = fi.error;
  772.         newTwistDownControl = (TTwistDownControl*)(FreeIfObject(newTwistDownControl));
  773.         //Don't ReSignal because we may be deep in the recursive AddTwistDownControls
  774.         //and we need to back out of a failure gracefully.
  775.     }
  776.     
  777. return newTwistDownControl;
  778. }
  779. //----------------------------------------------------------------------------------------
  780. // TTwistDownView::AddTwistDownControls:    used by
  781. //                                                                                TTwistDownView::CreateVisibleList:
  782. //                                                                                TTwistDownDocument::ExpandElement:
  783. //                                                                                TExpandAllCommand::DoIt:
  784. //----------------------------------------------------------------------------------------
  785. #pragma segment ARes
  786. void TTwistDownView::AddTwistDownControls(TTwistDownElement* twistDownElement, short &rowNumber, OSErr& myOSErr)
  787. {
  788.  
  789. VRect theVRect = gZeroVRect;
  790. VPoint twistDownControlLocation = gZeroVPt;
  791. TTwistDownControl* twistDownControl = NULL;
  792.  
  793. while (twistDownElement != NULL && myOSErr == noErr) 
  794.     {
  795.         ++rowNumber;
  796.         if (twistDownElement -> TestHasSubListFlag() && twistDownElement -> GetTwistDownControl() == NULL)
  797.             {            
  798.                 short rowHeight = this -> GetRowHeight(1);
  799.                 twistDownControlLocation.v = (long)(rowHeight*rowNumber - rowHeight);
  800.                 twistDownControlLocation.h = fTwistDownControlLocation.h;
  801.                 twistDownControl = this -> NewTwistDownControl(twistDownElement, twistDownControlLocation, myOSErr);
  802.                 twistDownElement -> SetTwistDownControlTo(twistDownControl);
  803.             }
  804.         
  805.         if (myOSErr == noErr)
  806.             {
  807.                 if (twistDownElement -> TestShowSubListFlag())
  808.                     this -> AddTwistDownControls(twistDownElement -> GetDescendantElement(), rowNumber, myOSErr);
  809.             
  810.                 twistDownElement = twistDownElement -> GetSuccessorElement();
  811.             }
  812.     }    
  813. }
  814. //----------------------------------------------------------------------------------------
  815. // TTwistDownView::DeleteTwistDownControls:
  816. //----------------------------------------------------------------------------------------
  817. #pragma segment ARes
  818. void TTwistDownView::DeleteTwistDownControls(TTwistDownElement* twistDownElement)
  819. {
  820.  
  821. while (twistDownElement != NULL) 
  822.     {
  823.         //Never remove twistDownControls from twistDownElements whose fIndentLevel == 0 because
  824.         //these elements are at the top of the hierarchy. Remove them and the user will never
  825.         //be able to descend the hierarchy.
  826.         
  827.         if (twistDownElement -> GetTwistDownControl() != NULL && twistDownElement -> GetIndentLevel() != 0)
  828.                 this -> RemoveTwistDownControl(twistDownElement);
  829.  
  830.         //There are no hidden twistDownControls. The only twistDownControls that exist
  831.         //are the ones you can see in the twistDownView. However, twistDownElements can have
  832.         //their fShowSubList set to TRUE even if they don't have a twistDownControl.
  833.         //Deleting a twistDowncontrol does not change the value of fShowSubList.
  834.         
  835.         if (twistDownElement -> TestShowSubListFlag())
  836.             this -> DeleteTwistDownControls(twistDownElement -> GetDescendantElement());
  837.             
  838.         twistDownElement = twistDownElement -> GetSuccessorElement();
  839.     }    
  840. }
  841. //----------------------------------------------------------------------------------------
  842. // TTwistDownView::RestoreTwistDownControls:
  843. //----------------------------------------------------------------------------------------
  844. #pragma segment ARes
  845. void TTwistDownView::RestoreTwistDownControls(TTwistDownElement* twistDownElement)
  846. {
  847. while (twistDownElement != NULL) 
  848.     {
  849.         //Never remove twistDownControls from twistDownElements whose fIndentLevel == 0 because
  850.         //these elements are at the top of the hierarchy. Remove them and the user will never
  851.         //be able to descend the hierarchy.
  852.         
  853.         if (twistDownElement -> GetTwistDownControl() != NULL 
  854.                     && twistDownElement -> GetIndentLevel() != 0
  855.                     && twistDownElement -> TestOldShowSubListFlag() != FALSE)
  856.                 {
  857.                 this -> RemoveTwistDownControl(twistDownElement);
  858.                 }
  859.             
  860.         if (twistDownElement -> TestShowSubListFlag())
  861.             this -> DeleteTwistDownControls(twistDownElement -> GetDescendantElement());
  862.             
  863.         twistDownElement = twistDownElement -> GetSuccessorElement();
  864.     }    
  865. }
  866. //----------------------------------------------------------------------------------------
  867. // TTwistDownView::RemoveTwistDownControl:
  868. //----------------------------------------------------------------------------------------
  869. #pragma segment ARes
  870. void TTwistDownView::RemoveTwistDownControl(TTwistDownElement* twistDownElement)
  871. {
  872.     TTwistDownControl* twistDownControl = NULL;
  873.     
  874.     twistDownControl = twistDownElement -> GetTwistDownControl();
  875.     
  876.     if (twistDownElement -> TestShowSubListFlag())
  877.         {
  878.             fNumberOfExpandedControls--;    //We're removing a control that was expanded.
  879.         }
  880.     else
  881.         fNumberOfCollapsedControls--;    //We're removing a control that was collapsed.
  882.         
  883.     this -> RemoveSubView(twistDownControl);
  884.     twistDownControl = (TTwistDownControl*)FreeIfObject(twistDownControl);
  885.                 
  886.     //Note: The TTwistDownControl::Free() method sets the fTwistDownControl field of
  887.     //the twistDownElement to NULL;
  888.  
  889. }
  890. //----------------------------------------------------------------------------------------
  891. // TTwistDownView::UpdateTwistDownControlLocations:    called by TTwistDownDocument::ExpandElement
  892. //                                                                                                                        TTwistDownDocument::CollapseElement
  893. //                                                                                                                        TTwistDownDocument::CollapseAll
  894. //                                                                                                                        TExpandAllCommand::DoIt
  895. //----------------------------------------------------------------------------------------
  896. #pragma segment ARes
  897. void TTwistDownView::UpdateTwistDownControlLocations(TTwistDownElement* twistDownElement, short &rowNumber)
  898. {
  899.  
  900. while (twistDownElement != NULL) 
  901.     {
  902.         ++rowNumber;
  903.         TTwistDownControl* twistDownControl = twistDownElement -> GetTwistDownControl();
  904.         if (twistDownControl != NULL)
  905.             twistDownControl -> UpdateControlLocationTo(rowNumber);
  906.             
  907.         if (twistDownElement -> TestShowSubListFlag())
  908.             this -> UpdateTwistDownControlLocations(twistDownElement -> GetDescendantElement(), rowNumber);
  909.             
  910.         twistDownElement = twistDownElement -> GetSuccessorElement();
  911.     }    
  912.  
  913. }
  914. //----------------------------------------------------------------------------------------
  915. // TTwistDownView::GetItemTextToDisplay: replaces GetItemText (could have been overloaded)
  916. //----------------------------------------------------------------------------------------
  917. #pragma segment ARes
  918. short TTwistDownView::GetItemTextToDisplay(short anItem, CStr63& aString)
  919. {
  920. MAVolatileInit(TTwistDownElement*, theTwistDownElement, NULL);
  921. TTwistDownControl* twistDownControl = NULL;
  922.  
  923. short rowNumber = 0;
  924. fTwistDownDocument -> GetTwistDownElementAt(anItem, fTwistDownDocument -> GetHeadOfList(), &theTwistDownElement, rowNumber);
  925. theTwistDownElement -> GetDisplayedText(aString);
  926. short indentLevel = theTwistDownElement -> GetIndentLevel();
  927. return indentLevel;
  928. }
  929. //----------------------------------------------------------------------------------------
  930. // TTwistDownView::GetTextToDisplay: replaces GetText (could have been overloaded)
  931. //----------------------------------------------------------------------------------------
  932. #pragma segment ARes
  933. short TTwistDownView::GetTextToDisplay(GridCell aCell, CStr63& aString)
  934. {
  935.     short indentLevel = this -> GetItemTextToDisplay(aCell.v, aString); //replaces GetItemText
  936.     return indentLevel;
  937. }
  938. //----------------------------------------------------------------------------------------
  939. // TTwistDownView::DrawCell:
  940. //----------------------------------------------------------------------------------------
  941. #pragma segment ARes
  942. void TTwistDownView::DrawCell(GridCell aCell, const VRect& aRect)// override 
  943. {
  944.     CStr63 theText;
  945.     short indentLevel;
  946.     
  947.     indentLevel = this -> GetTextToDisplay(aCell, theText);    //replaces GetText
  948.     
  949.     if (this -> GetColWidth(aCell.h) > 0)
  950.     {
  951.         CRect r;
  952.         short amountToIndent;
  953.     
  954.         amountToIndent = (indentLevel + 1)*fTwistDownControlSize.h;    //We need to add 1 to the indentLevel
  955.                                                                                                                                 //because the indentLevel of 
  956.                                                                                                                                 //twistDownControls at the top level 
  957.                                                                                                                                 //of the hierarchy is zero.
  958.         
  959.         this -> ViewToQDRect(aRect, r);
  960.         
  961.         //offset the rectangle here
  962.         if (fWritingDirection == leftToRight)
  963.             r.left = r.left + amountToIndent;
  964.         else
  965.             r.right = r.right - amountToIndent - 5;
  966.             
  967.         if(this->CanSelectCell(aCell))
  968.             MADrawString(theText, r, fJustification, fPreferOutline);
  969.         else
  970.         {
  971.             GrafPtr currentPort;
  972.             GetPort(¤tPort);
  973.  
  974.             PenState pState;
  975.             GetPenState(&pState);                // save pen state
  976.             short txMode = currentPort -> txMode;
  977.             
  978.             if (qNeedsColorQD || HasColorQD())
  979.                 TextMode(grayishTextOr);
  980.  
  981.             MADrawString(theText, r, fJustification, fPreferOutline);
  982.  
  983.             if (!(qNeedsColorQD || HasColorQD()))
  984.             {
  985.                 PenPat(&qd.gray);
  986.                 PenMode(patBic);
  987.                 PaintRect(r);
  988.             }
  989.  
  990.             SetPenState(&pState);                // restore pen state
  991.             TextMode(txMode);
  992.         }
  993.     }
  994. }
  995.  
  996. //----------------------------------------------------------------------------------------
  997. //TTwistDownView::GetNewFontSize:
  998. //----------------------------------------------------------------------------------------
  999. #pragma segment ADoCommand
  1000. Boolean TTwistDownView::GetNewFontSize(CommandNumber aCommandNumber,long& newFontSize)
  1001. {
  1002. #pragma unused aCommandNumber
  1003. Boolean result = FALSE;
  1004.     TChangeFontSizeDialog* aChangeFontSizeView = NULL;
  1005.     TWindow* aChangeFontSizeWindow = NULL;
  1006.     IDType dismisser;
  1007.     
  1008.     if (qTemplateViews)
  1009.         {                            
  1010.             FailNIL(aChangeFontSizeWindow = gViewServer -> NewTemplateWindow(kChangeFontSizeWindowID, NULL));
  1011.             aChangeFontSizeView = (TChangeFontSizeDialog*) (aChangeFontSizeWindow -> FindSubView(kChangeFontSizeViewID));
  1012.             aChangeFontSizeView -> SetNewSize(newFontSize);                                                                             
  1013.         }
  1014.  
  1015.     if (aChangeFontSizeWindow != NULL)
  1016.         {
  1017.             dismisser = aChangeFontSizeWindow -> PoseModally();
  1018.     
  1019.             if (dismisser == kDefaultOKItemID)
  1020.                 {
  1021.                     aChangeFontSizeView -> GetNewFontSize(newFontSize);
  1022.                     result = TRUE;
  1023.                 }
  1024.  
  1025.             aChangeFontSizeWindow -> CloseAndFree();
  1026.         }
  1027.         
  1028.     return result;
  1029. }
  1030. //----------------------------------------------------------------------------------------
  1031. // TTwistDownView::DoChangeTextStyle:
  1032. //----------------------------------------------------------------------------------------
  1033. #pragma segment ADoCommand
  1034. void TTwistDownView::DoChangeTextStyle(const TextStyle& itsTextStyle)
  1035. {
  1036. short rowHeight = 0;
  1037.  
  1038. GrafPtr savedPort;
  1039. GetPort(&savedPort);                    // save the port
  1040. SetPort(gWorkPort);                        // set port to the work port
  1041.  
  1042. SetPortTextStyle(itsTextStyle);            // set the port's text style
  1043. PenNormal();
  1044.  
  1045. FontInfo theFontInfo;
  1046. rowHeight = MAGetFontInfo(theFontInfo) + fRowInset;
  1047.  
  1048. SetPort(savedPort);                        // restore port
  1049.  
  1050. fTextStyle = itsTextStyle;
  1051. this -> SetUpFont();
  1052.  
  1053. this -> SetItemHeight(1,fNumOfRows,rowHeight);
  1054. this -> CreateTwistDownTriangles();
  1055.  
  1056. fTwistDownDocument -> InstallTextStyle(itsTextStyle);
  1057.  
  1058. short rowNumber = 0;
  1059.  
  1060. TTwistDownElement* headOfListElement = fTwistDownDocument -> GetHeadOfList();
  1061. if ( headOfListElement)
  1062.     {
  1063.         fTwistDownDocument -> UpdateTwistDownElements(headOfListElement, rowNumber);
  1064.         this -> ResizeTwistDownViewRows();
  1065.     }
  1066.  
  1067. }
  1068. //----------------------------------------------------------------------------------------
  1069. // TTwistDownView::DoChangeFontSize:
  1070. //----------------------------------------------------------------------------------------
  1071. #pragma segment ADoCommand
  1072. void TTwistDownView::DoChangeFontSize(short newFontSize)
  1073. {
  1074.     TextStyle newStyle = fTextStyle;    
  1075.     newStyle.tsSize = newFontSize;
  1076.     this -> DoChangeTextStyle(newStyle);
  1077. }
  1078. //----------------------------------------------------------------------------------------
  1079. // TTwistDownView::DoChangeFont:
  1080. //----------------------------------------------------------------------------------------
  1081. #pragma segment ADoCommand
  1082. void TTwistDownView::DoChangeFont(CStr255 newFontName)
  1083. {
  1084.     short fontNumber = 0;
  1085.     GetFNum(newFontName, &fontNumber);     //Moves memory. If it can't find newFontName, fontNumber
  1086.                                                                             //will be zero. The following if tests it and only does
  1087.                                                                             //the change if the font actually exists.
  1088.     if (fontNumber != 0)
  1089.         {
  1090.             TextStyle newStyle = fTextStyle;    
  1091.             GetFNum(newFontName, &(newStyle.tsFont));
  1092.             this -> DoChangeTextStyle(newStyle);
  1093.         }
  1094. }
  1095. //----------------------------------------------------------------------------------------
  1096. // TTwistDownView::DoChangeWritingDirection:
  1097. //----------------------------------------------------------------------------------------
  1098. #pragma segment ADoCommand
  1099. void TTwistDownView::DoChangeWritingDirection(EWritingDirection newWritingDirection)
  1100. {
  1101. fWritingDirection = newWritingDirection;
  1102.  
  1103. if (fWritingDirection == leftToRight)
  1104.         fJustification = teFlushDefault;
  1105. else
  1106.         fJustification = teFlushRight;
  1107.         
  1108. this -> CreateTwistDownTriangles();
  1109.  
  1110. short rowNumber = 0;
  1111.  
  1112. TTwistDownElement* headOfListElement = fTwistDownDocument -> GetHeadOfList();
  1113. if ( headOfListElement)
  1114.     {
  1115.         fTwistDownDocument -> UpdateTwistDownElements(headOfListElement, rowNumber);
  1116.         
  1117.         if (fWritingDirection == leftToRight)
  1118.             this -> RevealTop(kRedraw);
  1119.         else
  1120.             this -> RevealRight(kRedraw);
  1121.             
  1122.     }
  1123. }
  1124. //----------------------------------------------------------------------------------------
  1125. // TTwistDownView::GetTwistDownControlSize:
  1126. //----------------------------------------------------------------------------------------
  1127. #pragma segment ARes
  1128. VPoint TTwistDownView::GetTwistDownControlSize()
  1129. {
  1130. return fTwistDownControlSize;
  1131. }
  1132. //----------------------------------------------------------------------------------------
  1133. // TTwistDownView::CreateTwistDownTriangles:
  1134. //----------------------------------------------------------------------------------------
  1135. #pragma segment ARes
  1136. void TTwistDownView::CreateTwistDownTriangles()
  1137. {
  1138. short                twistDownControlSize;
  1139. short                halfSize;
  1140. short                intermediateSize;
  1141. FontInfo        theFontInfo;
  1142. short                theFontHeight;
  1143. OSErr                myQDError = noErr;
  1144.  
  1145. theFontHeight = MAGetFontInfo(theFontInfo);
  1146. fTwistDownControlSize.v = theFontHeight;
  1147.  
  1148. twistDownControlSize = theFontInfo.ascent;
  1149. twistDownControlSize &= ~1;                        /* Round down to an even number    */
  1150. halfSize = twistDownControlSize / 2;
  1151. intermediateSize = (twistDownControlSize * 3) / 4;
  1152.  
  1153. FailInfo fi;
  1154. Try(fi)
  1155.     {
  1156.  
  1157. //First, get rid of the existing triangles. The triangles do not exist for a new TTwistDownView.
  1158. //However, when changing the format of the TTwistDownView, they do exist. Anytime the font or
  1159. //its size are changed, the triangles are created again.
  1160.  
  1161.         if (fOpenTriangle)
  1162.             {
  1163.                 KillPoly(fOpenTriangle);
  1164.                 FailOSErr(QDError());
  1165.                 fOpenTriangle = NULL;
  1166.             }
  1167.  
  1168.         if (fClosedTriangle)
  1169.             {
  1170.                 KillPoly(fClosedTriangle);
  1171.                 FailOSErr(QDError());
  1172.                 fClosedTriangle = NULL;
  1173.             }
  1174.             
  1175.         if (fIntermediateTriangle)
  1176.             {
  1177.                 KillPoly(fIntermediateTriangle);
  1178.                 FailOSErr(QDError());
  1179.                 fIntermediateTriangle = NULL;
  1180.             }
  1181.                     
  1182.         fOpenTriangle = OpenPoly();
  1183.             FailOSErr(QDError());
  1184.             MoveTo(0, halfSize);
  1185.             LineTo(twistDownControlSize, halfSize);
  1186.             LineTo(halfSize, twistDownControlSize);
  1187.             LineTo(0, halfSize);
  1188.             ClosePoly();
  1189.             FailOSErr(QDError());
  1190.  
  1191.         fTwistDownControlSize.h = (**fOpenTriangle).polyBBox.right + kTriangleOutsideGap + kTriangleInsideGap;
  1192.         
  1193.         if (fWritingDirection == leftToRight)
  1194.             fTwistDownControlLocation.h = 0;
  1195.         else
  1196.             fTwistDownControlLocation.h = fSize.h - fTwistDownControlSize.h;        
  1197.     
  1198. //In a normal application, I would use        
  1199. //    short sysDirection = GetSysDirection();
  1200. //    if (sysDirection == 0)        
  1201. //instead of         
  1202. //    if (fWritingDirection == leftToRight)
  1203. //That is because GetSysDirection() returns the system direction for the system font and
  1204. //not the application font. Here we're testing so it is necessary to fake it and pretend
  1205. //we're running on an Arabic or Hebrew system.
  1206.  
  1207.         if (fWritingDirection == leftToRight)
  1208.             {
  1209.                 fClosedTriangle = OpenPoly();
  1210.                     FailOSErr(QDError());
  1211.                     MoveTo(halfSize, 0);
  1212.                     LineTo(twistDownControlSize, halfSize);
  1213.                     LineTo(halfSize, twistDownControlSize);
  1214.                     LineTo(halfSize, 0);
  1215.                 ClosePoly();
  1216.                 FailOSErr(QDError());
  1217.         
  1218.                 fIntermediateTriangle = OpenPoly();
  1219.                     FailOSErr(QDError());
  1220.                     MoveTo(intermediateSize, 0);
  1221.                     LineTo(intermediateSize, intermediateSize);
  1222.                     LineTo(0, intermediateSize);
  1223.                     LineTo(intermediateSize, 0);
  1224.                 ClosePoly();
  1225.                 FailOSErr(QDError());
  1226.             }
  1227.         else        /* Arabic/Hebrew triangles        */
  1228.             {
  1229.     
  1230.                 fClosedTriangle = OpenPoly();
  1231.                     FailOSErr(QDError());
  1232.                     MoveTo(twistDownControlSize - halfSize, 0);
  1233.                     LineTo(0, halfSize);
  1234.                     LineTo(twistDownControlSize - halfSize, twistDownControlSize);
  1235.                     LineTo(twistDownControlSize - halfSize, 0);
  1236.                 ClosePoly();
  1237.                 FailOSErr(QDError());
  1238.             
  1239.                 fIntermediateTriangle = OpenPoly();
  1240.                     FailOSErr(QDError());
  1241.                     MoveTo(twistDownControlSize - intermediateSize, 0);
  1242.                     LineTo(twistDownControlSize - intermediateSize, intermediateSize);
  1243.                     LineTo(twistDownControlSize, intermediateSize);
  1244.                     LineTo(twistDownControlSize - intermediateSize, 0);
  1245.                 ClosePoly();
  1246.                 FailOSErr(QDError());
  1247.             }
  1248.         fi.Success();
  1249.     }
  1250. else
  1251.     {
  1252.         if (fOpenTriangle)
  1253.             {
  1254.                 KillPoly(fOpenTriangle);
  1255.                 fOpenTriangle = NULL;
  1256.             }
  1257.  
  1258.         if (fClosedTriangle)
  1259.             {
  1260.                 KillPoly(fClosedTriangle);
  1261.                 fClosedTriangle = NULL;
  1262.             }
  1263.         
  1264.         if (fIntermediateTriangle)
  1265.             {
  1266.                 KillPoly(fIntermediateTriangle);
  1267.                 fIntermediateTriangle = NULL;
  1268.             }
  1269.                     
  1270.         fi.ReSignal();
  1271.     }
  1272.  
  1273. }
  1274. //----------------------------------------------------------------------------------------
  1275. // TTwistDownView::GetOpenTriangle:
  1276. //----------------------------------------------------------------------------------------
  1277. #pragma segment ARes
  1278. PolyHandle TTwistDownView::GetOpenTriangle()
  1279. {
  1280. return fOpenTriangle;
  1281. }
  1282. //----------------------------------------------------------------------------------------
  1283. // TTwistDownView::GetClosedTriangle:
  1284. //----------------------------------------------------------------------------------------
  1285. #pragma segment ARes
  1286. PolyHandle TTwistDownView::GetClosedTriangle()
  1287. {
  1288. return fClosedTriangle;
  1289. }
  1290. //----------------------------------------------------------------------------------------
  1291. // TTwistDownView::GetIntermediateTriangle:
  1292. //----------------------------------------------------------------------------------------
  1293. #pragma segment ARes
  1294. PolyHandle TTwistDownView::GetIntermediateTriangle()
  1295. {
  1296. return fIntermediateTriangle;
  1297. }
  1298. //----------------------------------------------------------------------------------------
  1299. // TTwistDownView::IncrementNumberOfControls:
  1300. //----------------------------------------------------------------------------------------
  1301. #pragma segment ADoCommand
  1302. void TTwistDownView::IncrementNumberOfControls()
  1303. {
  1304. fNumberOfControls++;
  1305. }
  1306. //----------------------------------------------------------------------------------------
  1307. // TTwistDownView::DecrementNumberOfControls:
  1308. //----------------------------------------------------------------------------------------
  1309. #pragma segment ADoCommand
  1310. void TTwistDownView::DecrementNumberOfControls()
  1311. {
  1312. fNumberOfControls--;
  1313. }
  1314. //----------------------------------------------------------------------------------------
  1315. // TTwistDownView::GetNumberOfControls:
  1316. //----------------------------------------------------------------------------------------
  1317. #pragma segment ADoCommand
  1318. long TTwistDownView::GetNumberOfControls()
  1319. {
  1320. return fNumberOfControls;
  1321. }
  1322.  
  1323. //----------------------------------------------------------------------------------------
  1324. // TTwistDownView::IncrementNumberOfExpandedControls:
  1325. //----------------------------------------------------------------------------------------
  1326. #pragma segment ADoCommand
  1327. void TTwistDownView::IncrementNumberOfExpandedControls()
  1328. {
  1329. fNumberOfExpandedControls++;
  1330. }
  1331. //----------------------------------------------------------------------------------------
  1332. // TTwistDownView::DecrementNumberOfExpandedControls:
  1333. //----------------------------------------------------------------------------------------
  1334. #pragma segment ADoCommand
  1335. void TTwistDownView::DecrementNumberOfExpandedControls()
  1336. {
  1337. fNumberOfExpandedControls--;
  1338. }
  1339. //----------------------------------------------------------------------------------------
  1340. // TTwistDownView::IncrementNumberOfCollapsedControls:
  1341. //----------------------------------------------------------------------------------------
  1342. #pragma segment ADoCommand
  1343.  
  1344. void TTwistDownView::IncrementNumberOfCollapsedControls()
  1345. {
  1346. fNumberOfCollapsedControls++;
  1347. }
  1348. //----------------------------------------------------------------------------------------
  1349. // TTwistDownView::DecrementNumberOfCollapsedControls:
  1350. //----------------------------------------------------------------------------------------
  1351. #pragma segment ADoCommand
  1352. void TTwistDownView::DecrementNumberOfCollapsedControls()
  1353. {
  1354. fNumberOfCollapsedControls--;
  1355. }
  1356.  
  1357. //The following four methods are used to manage error recover from failed
  1358. //TExpandAllCommands
  1359. //----------------------------------------------------------------------------------------
  1360. // TTwistDownView::GetNumberOfExpandedControls:
  1361. //----------------------------------------------------------------------------------------
  1362. #pragma segment ADoCommand
  1363. long TTwistDownView::GetNumberOfExpandedControls()
  1364. {
  1365. return fNumberOfExpandedControls;
  1366. }
  1367. //----------------------------------------------------------------------------------------
  1368. // TTwistDownView::SetNumberOfExpandedControlsTo:
  1369. //----------------------------------------------------------------------------------------
  1370. #pragma segment ADoCommand
  1371. void TTwistDownView::SetNumberOfExpandedControlsTo(long numberOfControls)
  1372. {
  1373. fNumberOfExpandedControls = numberOfControls;
  1374. }
  1375. //----------------------------------------------------------------------------------------
  1376. // TTwistDownView::GetNumberOfCollapsedControls:
  1377. //----------------------------------------------------------------------------------------
  1378. #pragma segment ADoCommand
  1379.  
  1380. long TTwistDownView::GetNumberOfCollapsedControls()
  1381. {
  1382. return fNumberOfCollapsedControls;
  1383. }
  1384. //----------------------------------------------------------------------------------------
  1385. // TTwistDownView::SetNumberOfCollapsedControlsTo:
  1386. //----------------------------------------------------------------------------------------
  1387. #pragma segment ADoCommand
  1388. void TTwistDownView::SetNumberOfCollapsedControlsTo(long numberOfControls)
  1389. {
  1390. fNumberOfCollapsedControls = numberOfControls;
  1391. }
  1392. //----------------------------------------------------------------------------------------
  1393. // TTwistDownView::SetCantExpandAll: used by TExpandAllCommand::DoIt:
  1394. //----------------------------------------------------------------------------------------
  1395. //This is called just after the ExpandAll command has been done.
  1396. #pragma segment ADoCommand
  1397. void TTwistDownView::SetCantExpandAll()
  1398. {
  1399.     fNumberOfExpandedControls = fNumberOfControls;
  1400.     fNumberOfCollapsedControls = 0;
  1401.     this -> SetTheCouldFlags();
  1402. }
  1403. //----------------------------------------------------------------------------------------
  1404. // TTwistDownView::SetCantCollapseAll: used by TCollapseAllCommand::DoIt:
  1405. //----------------------------------------------------------------------------------------
  1406. //This is called just after the CollapseAll command has been done.
  1407. #pragma segment ADoCommand
  1408. void TTwistDownView::SetCantCollapseAll()
  1409. {
  1410.     fNumberOfExpandedControls = 0;
  1411.     fNumberOfCollapsedControls = fNumberOfControls;
  1412.     this -> SetTheCouldFlags();
  1413. }
  1414.  
  1415. //----------------------------------------------------------------------------------------
  1416. // TTwistDownView::SetTheCouldFlags:    called by
  1417. //                                                                        TTwistDownView::CreateVisibleList: (when the list is first created)
  1418. //                                                                        TTwistDownView::SetCantExpandAll:
  1419. //                                                                        TTwistDownView::SetCantCollapseAll:
  1420. //                                                                        TTwistDownDocument::ExpandElement:
  1421. //                                                                        TTwistDownDocument::CollapseElement:
  1422. //                                                                        TTwistDownDocument::CollapseAll:
  1423. //                                                                        TExpandAllCommand::DoIt: (failure recovery part)
  1424. //                                                                        TCollapseElementCommand::DoIt()
  1425. //----------------------------------------------------------------------------------------
  1426. #pragma segment ARes
  1427. void TTwistDownView::SetTheCouldFlags()
  1428. {
  1429.         
  1430.     fCouldExpandAll = FALSE;
  1431.     fCouldCollapseAll = FALSE;
  1432.     
  1433.     if (fNumberOfExpandedControls > 0)
  1434.         fCouldCollapseAll = TRUE;
  1435.     
  1436.     if (fNumberOfCollapsedControls > 0 && fTwistDownDocument -> GetNumberOfItemsInList() <= (long)kMaxNumberOfItemsToDisplay)
  1437.         fCouldExpandAll = TRUE;
  1438.  
  1439. }
  1440. //----------------------------------------------------------------------------------------
  1441. // TTwistDownView::IncrementInitialNumberOfControls: Used
  1442. //----------------------------------------------------------------------------------------
  1443. //This is used only by TTwistDownControl::ITwistDownControl and then only if
  1444. //TTwistDownView::ControlCountingEnabled() returns FALSE. 
  1445. #pragma segment AOpen
  1446. void TTwistDownView::IncrementInitialNumberOfControls()
  1447. {
  1448. fInitialNumberOfControls++;
  1449. }
  1450.  
  1451. //----------------------------------------------------------------------------------------
  1452. // TTwistDownView::ControlCountingEnabled:
  1453. //----------------------------------------------------------------------------------------
  1454. //This is used only by TTwistDownControl::ITwistDownControl.
  1455. //Once the twistDownDocument has been read in and the intiial controls have been made, 
  1456. //fControlCountingEnabled is set to TRUE for the life of the twistDownDocument.
  1457. #pragma segment ARes
  1458. Boolean TTwistDownView::ControlCountingEnabled()
  1459. {
  1460. return fControlCountingEnabled;
  1461. }
  1462.  
  1463.  
  1464. //----------------------------------------------------------------------------------------
  1465. // TTwistDownView::DoScriptCommand:        Scripting Support    
  1466. //----------------------------------------------------------------------------------------
  1467. #pragma segment MAScriptingRes
  1468. void TTwistDownView::DoScriptCommand(CommandNumber aCommandNumber, TAppleEvent* message, TAppleEvent* reply)
  1469. {
  1470.  
  1471. switch (aCommandNumber)
  1472.     {
  1473.         case cExpandAll:
  1474.             {
  1475.                 if (fCouldExpandAll)    //See note in TTwistDownDocument::DoScriptCommand
  1476.                     {
  1477.                         long objectHeapSpaceRequired = long((fTwistDownDocument -> GetNumberOfDirectoriesInList() 
  1478.                                                                                     - fNumberOfControls)*(gTwistDownApp -> fTDControlClassSize));
  1479.                                                                                     
  1480.                         Boolean haveHeapSpace = HaveObjectHeapSpace(objectHeapSpaceRequired + 3*1024);
  1481.                         
  1482.                         if (haveHeapSpace)
  1483.                             {
  1484.                                 TExpandAllCommand* anExpandAllCommand = new TExpandAllCommand;
  1485.                                 anExpandAllCommand -> IExpandAllCommand(fTwistDownDocument,this, 
  1486.                                                                                                                 message -> fMessage, reply -> fMessage);
  1487.                                 
  1488.                                 this -> PostCommand(anExpandAllCommand);    
  1489.                             }
  1490.                         else
  1491.                             Failure(memFullErr, 0);                                
  1492.                     }
  1493.                 else
  1494.                     FailOSErr(errListAlreadyExpanded);                    
  1495.             }
  1496.             break;
  1497.             
  1498.         case cCollapseAll:
  1499.             {
  1500.                 if (fCouldCollapseAll)
  1501.                     {
  1502.                     //Because we don't want this to fail for out of memory reasons,
  1503.                     //allocate it from temporary memory.    //PGMacApp 550
  1504.                         Boolean oldTemp = TemporaryAllocation(TRUE);
  1505.                         Boolean oldArrayPerm = AllocateObjectsFromPerm(FALSE);
  1506.                             TCollapseAllCommand* aCollapseAllCommand = new TCollapseAllCommand;
  1507.                             aCollapseAllCommand -> ICollapseAllCommand(fTwistDownDocument, this, 
  1508.                                                                                                                 message -> fMessage, reply -> fMessage);
  1509.                             
  1510.                             this -> PostCommand(aCollapseAllCommand);
  1511.                         oldArrayPerm = AllocateObjectsFromPerm(oldArrayPerm);    
  1512.                         oldTemp = TemporaryAllocation(oldTemp);
  1513.                     }
  1514.                 else
  1515.                     FailOSErr(errListAlreadyCollapsed);
  1516.             }
  1517.             break;
  1518.  
  1519.         default:
  1520.             {        
  1521.                 MScriptableObject::DoScriptCommand(aCommandNumber, message, reply);
  1522.             }
  1523.             break;
  1524.     }
  1525.  
  1526. }
  1527. //----------------------------------------------------------------------------------------
  1528. // TTwistDownView::GetSpecifierForm:        Scripting Support    
  1529. //----------------------------------------------------------------------------------------
  1530. #pragma segment MAScriptingRes
  1531. DescType TTwistDownView::GetSpecifierForm()
  1532. {
  1533.     return formName;
  1534. }
  1535. //----------------------------------------------------------------------------------------
  1536. // TTwistDownView::GetObjectProperty:        Scripting Support
  1537. //----------------------------------------------------------------------------------------
  1538. #pragma segment MAScriptingRes
  1539. Boolean TTwistDownView::GetObjectProperty(CAEDesc& thePropertyValue,
  1540.                                         DescType whichProperty,
  1541.                                         const CAEDesc& desiredType)
  1542. {
  1543.     // Return properties for the twistDownView
  1544.  
  1545. Boolean hasProperty = TRUE;
  1546.  
  1547.     FailInfo fi;
  1548.     Try(fi)
  1549.     {
  1550.         switch (whichProperty)
  1551.         {
  1552.     
  1553.             case pName:
  1554.                 CStr255 theName;
  1555.                 theName = fTwistDownDocument -> fTitle;            
  1556.                 thePropertyValue.PutString(theName);
  1557.                 break;
  1558.  
  1559.             case pFontName:
  1560.                 CStr255 theFontName;
  1561.                 short theFontNum = fTextStyle.tsFont;
  1562.                 GetFontName(theFontNum, theFontName);
  1563.                 thePropertyValue.PutString(theFontName);
  1564.                 break;
  1565.                 
  1566.             case pPointSize:    
  1567.                 long itsSize = (long)fTextStyle.tsSize;    
  1568.                 thePropertyValue.PutLong(itsSize);
  1569.                 break;
  1570.  
  1571.             case pCouldExpand:        
  1572.                 thePropertyValue.PutBoolean(fCouldExpandAll);
  1573.                 break;
  1574.                 
  1575.             case pCouldCollapse:        
  1576.                 thePropertyValue.PutBoolean(fCouldCollapseAll);
  1577.                 break;
  1578.  
  1579.             case pWritingDirection:
  1580.                 {    
  1581.                     DescType theWritingDirection;
  1582.                     
  1583.                     if (fWritingDirection == leftToRight)
  1584.                         theWritingDirection = kAELeftToRight;
  1585.                     else if (fWritingDirection == rightToLeft)
  1586.                         theWritingDirection = kAERightToLeft;
  1587.                         
  1588.                     thePropertyValue.PutEnum(theWritingDirection);
  1589.                 }
  1590.                 break;
  1591.  
  1592.             default:
  1593.                 hasProperty = MScriptableObject::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
  1594.                 break;
  1595.         }
  1596.         fi.Success();
  1597.     }
  1598.     else
  1599.     {
  1600.         // we failed while trying to get the property
  1601.         hasProperty = FALSE;
  1602.         
  1603.         // Don't ReSignal
  1604.     }
  1605.     return hasProperty;
  1606. }
  1607. //----------------------------------------------------------------------------------------
  1608. // TTwistDownView::GetSetPropertyInfo:        Scripting Support
  1609. //----------------------------------------------------------------------------------------
  1610. #pragma segment MAScriptingRes
  1611. void TTwistDownView::GetSetPropertyInfo(DescType whichProperty,
  1612.                                 CommandNumber& cmdNum,
  1613.                                 Boolean& canUndo,
  1614.                                 Boolean& causesChange,
  1615.                                 TCommandHandler* &theContext)
  1616. {
  1617.  
  1618. switch(whichProperty)
  1619.     {
  1620.     
  1621.         case pFontName:
  1622.             cmdNum = cChangeFont;
  1623.             canUndo = FALSE;
  1624.             causesChange = FALSE;
  1625.             theContext = this;
  1626.             break;
  1627.             
  1628.         case pPointSize:
  1629.             cmdNum = cChangeFontSize;
  1630.             canUndo = FALSE;
  1631.             causesChange = FALSE;
  1632.             theContext = this;
  1633.             break;
  1634.             
  1635.         case pWritingDirection:
  1636.             cmdNum = cChangeWritingDirection;
  1637.             canUndo = FALSE;
  1638.             causesChange = FALSE;
  1639.             theContext = this;
  1640.             break;
  1641.  
  1642.         default:
  1643.             MScriptableObject::GetSetPropertyInfo(whichProperty, cmdNum, canUndo, causesChange, theContext);
  1644.             break;
  1645.     }
  1646. }
  1647. //----------------------------------------------------------------------------------------
  1648. // TTwistDownView::SetObjectProperty:        Scripting Support
  1649. //----------------------------------------------------------------------------------------
  1650. #pragma segment MAScriptingRes
  1651. void TTwistDownView::SetObjectProperty(const CAEDesc& thePropertyValue,
  1652.                                              DescType whichProperty)
  1653. {
  1654. //I'm ambivalent about whether it makes sense to allow a script to change the font, its size,
  1655. //or the writing direction if the list is empty. We wouldn't allow it from the menu. For the 
  1656. //sake of argument, let's not allow it here but allow it in TTwistDownDocument::SetObjectProperty.
  1657.     long numberOfItemsInList = 0;
  1658.     
  1659.     if (fTwistDownDocument)
  1660.         numberOfItemsInList = fTwistDownDocument -> GetNumberOfItemsInList();
  1661.         
  1662. switch (whichProperty)
  1663.     {
  1664.         case pName:        
  1665.             CStr255 theDocName;
  1666.             thePropertyValue.GetString(theDocName);
  1667.             fTwistDownDocument -> SetTitle(theDocName);
  1668.             break;
  1669.  
  1670.             case pFontName:
  1671.                 CStr255 newFontName;
  1672.                 thePropertyValue.GetString(newFontName,255);
  1673.                 if (numberOfItemsInList > 0)
  1674.                     this -> DoChangeFont(newFontName);
  1675.                 break;
  1676.                 
  1677.             case pPointSize:
  1678.                 short newFontSize = 0;    
  1679.                 newFontSize = (short)thePropertyValue.GetLong();
  1680.                 if (numberOfItemsInList > 0)                
  1681.                     this -> DoChangeFontSize(newFontSize);
  1682.                 break;
  1683.  
  1684.             case pWritingDirection:
  1685.                 {    
  1686.                     DescType theWritingDirection = thePropertyValue.GetEnum();
  1687.                     EWritingDirection newWritingDirection = leftToRight;
  1688.                     
  1689.                     if (theWritingDirection == kAELeftToRight)
  1690.                         newWritingDirection = leftToRight;
  1691.                     else
  1692.                         newWritingDirection = rightToLeft;
  1693.                     
  1694.                     //From a script, it is possible to tell a twistDownView to change
  1695.                     //the writing direction to the same writing direction, ie. no change.
  1696.                     //Here we make sure it is actually going to change before proceeding.
  1697.                     if (newWritingDirection != fWritingDirection && numberOfItemsInList > 0)
  1698.                         this -> DoChangeWritingDirection(newWritingDirection);
  1699.  
  1700.                 }
  1701.                 break;
  1702.  
  1703.         default:
  1704.             MScriptableObject::SetObjectProperty(thePropertyValue, whichProperty);
  1705.             break;
  1706.     }
  1707. }
  1708. //========================================================================================
  1709. // CLASS TChangeFontSizeDialog
  1710. //========================================================================================
  1711. #undef Inherited
  1712. #define Inherited TView
  1713.  
  1714. #pragma segment ADoCommand
  1715. MA_DEFINE_CLASS_M1(TChangeFontSizeDialog, Inherited);
  1716.  
  1717. //----------------------------------------------------------------------------------------
  1718. // TChangeFontSizeDialog constructor
  1719. //----------------------------------------------------------------------------------------
  1720. #pragma segment ConstructorRes
  1721. TChangeFontSizeDialog::TChangeFontSizeDialog()  
  1722. {
  1723. #if qDebug
  1724. this -> PrintAppConstructorClassInfo();
  1725. #endif
  1726. }
  1727. //----------------------------------------------------------------------------------------
  1728. // TChangeFontSizeDialog::~TChangeFontSizeDialog
  1729. //----------------------------------------------------------------------------------------
  1730. #pragma segment MADestructorRes
  1731. TChangeFontSizeDialog::~TChangeFontSizeDialog()
  1732. {
  1733. #if qDebug
  1734. this -> PrintAppDestructorClassInfo();
  1735. #endif
  1736. }
  1737. //----------------------------------------------------------------------------------------
  1738. // TChangeFontSizeDialog::IChangeFontSizeDialog:
  1739. //----------------------------------------------------------------------------------------
  1740. #pragma segment ASelCommand
  1741. void TChangeFontSizeDialog::IChangeFontSizeDialog(TDocument* itsDocument,TView* itsSuperView,
  1742.                   const VPoint& itsLocation,const VPoint& itsSize,SizeDeterminer itsHSizeDet,SizeDeterminer itsVSizeDet)
  1743. {
  1744. this -> IView(itsDocument,itsSuperView,itsLocation,itsSize,itsHSizeDet,itsVSizeDet);
  1745.  
  1746. }
  1747. //----------------------------------------------------------------------------------------
  1748. // TChangeFontSizeDialog::GetNewFontSize:
  1749. //----------------------------------------------------------------------------------------
  1750. #pragma segment ADoCommand
  1751. void TChangeFontSizeDialog::GetNewFontSize(long& newSize)
  1752. {
  1753. TNumberText* fontSizeValue = NULL;
  1754.  
  1755. fontSizeValue = (TNumberText*) (this -> FindSubView(kSizeValueViewID));
  1756. newSize = fontSizeValue -> GetValue();
  1757. }
  1758. //----------------------------------------------------------------------------------------
  1759. // TChangeFontSizeDialog::SetNewSize:
  1760. //----------------------------------------------------------------------------------------
  1761. #pragma segment ADoCommand
  1762. void TChangeFontSizeDialog::SetNewSize(long& newSize)
  1763. {
  1764. TNumberText* fontSizeValue = NULL;
  1765.  
  1766. fontSizeValue = (TNumberText*) (this -> FindSubView(kSizeValueViewID));
  1767. fontSizeValue -> SetValue(newSize, TRUE);
  1768. }
  1769.  
  1770.  
  1771.  
  1772. #pragma segment Inline